$.fn.serializeObject = function() 
{  

	var o = {};  

	var a = this.serializeArray();  

	$.each(a, function() {  

	 if (o[this.name]) {  

			if (!o[this.name].push) {  

			   o[this.name] = [ o[this.name] ];  

			  }  

				 o[this.name].push(this.value || '');  

		  } else {  

			   o[this.name] = this.value || '';  

		   }  

	   });  

		return o;  

} 
function paramString2obj (serializedParams) { 
      

     var obj={};  

     function evalThem (str) {  

         var attributeName = str.split("=")[0];  

       var attributeValue = str.split("=")[1];  

         //if(!attributeValue){  

           // return ;  

       //}  
      var array = attributeName.split(".");
       for (var i = 1; i < array.length; i++) {
             var tmpArray = Array();
             tmpArray.push("obj");
            for (var j = 0; j < i; j++) {
               tmpArray.push(array[j]);
           };
            var evalString = tmpArray.join(".");
        // alert(evalString);
            if(!eval(evalString)){
               eval(evalString+"={};");
            }
      };
        eval("obj."+attributeName+"=\""+attributeValue+"\";");
    };
    var properties = serializedParams.split("&");
     for (var i = 0; i < properties.length; i++) {
         evalThem(properties[i]);
  };

 

  return obj;  

}  
/************************************** 表单序列化JSON字符串 **************************************/
 $.fn.form2str = function(){
      return JSON.stringify(paramString2obj(this.serialize()));
} 
/************************************ 表单序列化为JSON对象 **************************************/
 $.fn.form2json = function(){
     return paramString2obj(this.serialize());
}

// 重写jquery 参数转换方法 add by zengzh 2011-03-12 17:50
function  param( a, traditional ) {
		var s = [],
			add = function( key, value ) {
				// If value is a function, invoke it and return its value
				value = jQuery.isFunction(value) ? value() : value;
				value = value.replace(/\\/g,'\\\\').replace(/\"/g,'\\\"');
				s[ s.length ] = encodeURIComponent(key) + "=" + encodeURIComponent(value);
			};
		
		// Set traditional to true for jQuery <= 1.3.2 behavior.
		if ( traditional === undefined ) {
			traditional = jQuery.ajaxSettings.traditional;
		}
		
		// If an array was passed in, assume that it is an array of form elements.
		if ( jQuery.isArray(a) || a.jquery ) {
			// Serialize the form elements
			jQuery.each( a, function() {
				add( this.name, this.value );
			});
		} else {
			// If traditional, encode the "old" way (the way 1.3.2 or older
			// did it), otherwise encode params recursively.
			for ( var prefix in a ) {
				buildParams( prefix, a[prefix], traditional, add );
			}
		}
		// Return the resulting serialization
		return s.join("&");//.replace(/%20/g, "+");
	}
